from rest_framework import serializers

from app1.models import ShiBieModels

class ShibieSerializer(serializers.ModelSerializer):
    status_display = serializers.SerializerMethodField()
    class Meta:
        model = ShiBieModels
        fields = ('id','image_name','time','people','nohelmet_people','status','status_display','confidences','video_name','frame_details')

    def get_status_display(self, obj):
        # 获取fenlei字段的选项描述
        # status_value = obj.get('status', -1)  # 设置默认值-1表示未知
        return dict(self.Meta.model.status_choices).get(obj.status, '2')
        # return dict(shibie.status_choices).get(obj.status, '2')